package com.nenude.corejava.ch10;

import java.util.TreeSet;

public class TreeSetCalss {

	public static void main(String[] args) {
		
		//TreeSet保存的数据类型需要实现java.lang.Comparable接口
		//在保存数据时会进行类型检查，如果没有实现java.lang.Comparable接口会报类型转换异常java.lang.classcastException
		
		TreeSet<Computer> treeSet=new TreeSet<Computer>();
		treeSet.add(new Computer("HP1",5000));
		treeSet.add(new Computer("HP3",5000));
		treeSet.add(new Computer("HP2",5000));
		treeSet.add(new Computer("HW6",5000));
		treeSet.add(new Computer("HW2",5000));
		treeSet.add(new Computer("HW4",5000));
		treeSet.add(new Computer("dell4",5000));
		treeSet.add(new Computer("dell2",5000));
		treeSet.add(new Computer("dell3",5000));
		
		Computer computer=treeSet.first();
		Computer computer2=treeSet.last();
		System.out.println(computer);
		System.out.println(computer2);
		
		//以队列形式进行取数据操作
		System.out.println("=======================");
		//computer=treeSet.pollFirst();
		computer=treeSet.pollLast();//先进后出
		while (computer!=null) {
		System.out.println(computer);
		computer=treeSet.pollFirst();
			
		}
		

	}

}
